import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import './styles/index.scss'
import './api' // 导入API配置

// 全局配置
Vue.config.productionTip = false
Vue.use(ElementUI, {
  size: 'small', // 默认组件尺寸
  zIndex: 3000 // 弹框默认z-index
})

// 全局过滤器 - 日期格式化
import moment from 'moment'
Vue.filter('formatDate', function(value, format = 'YYYY-MM-DD HH:mm:ss') {
  if (!value) return ''
  return moment(value).format(format)
})

// 全局指令 - 权限控制
Vue.directive('permission', {
  inserted: function(el, binding) {
    const { value } = binding
    const permissions = store.getters.permissions || []
    
    if (value && !permissions.includes(value)) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
